package com.ctshk.app.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.tour.dto.*;
import com.ctshk.rpc.tour.dto.cache.*;
import com.ctshk.rpc.tour.req.BranchQueryReq;
import com.ctshk.rpc.tour.req.FavoritesReq;
import com.ctshk.rpc.tour.req.LocalHotSearchReq;
import com.ctshk.rpc.tour.req.es.TripDetailsDateReq;
import com.ctshk.rpc.tour.req.es.TripDetailsReq;
import com.ctshk.rpc.tour.req.es.TripRecommendReq;
import com.ctshk.rpc.tour.req.es.TripSearchReq;
import com.ctshk.rpc.tour.service.ISeriesTripAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系列团行程 H5前端控制器
 * </p>
 *
 * @author 廖胤松
 * @since 2021-05-17
 */
@Api(value = "旅行团-APP-App&H5端", tags = "旅行团-APP-App&H5端")
@RestController
@RequestMapping("/series/trip/h5")
public class SeriesTripH5Controller extends BaseController {

    @DubboReference
    private ISeriesTripAppService iSeriesTripAppService;

    @ApiOperation(value = "旅行团首页—当季热卖分类&通告&banner", notes = "旅行团首页—当季热卖分类&通告")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页—当季热卖分类&通告", operDesc = "旅行团首页—当季热卖分类&通告")
    @GetMapping("/home/type-msg")
    public Result<TourHomeHotTypeAndMsgDTO> tripHotTypeAndMsgInfo() {
        return Result.success(iSeriesTripAppService.tripHotTypeAndMsgInfo());
    }

    @ApiOperation(value = "旅行团首页—当季热卖-搜素", notes = "旅行团首页-当季热卖-搜索")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页-当季热卖-搜索", operDesc = "旅行团首页-当季热卖-搜索")
    @PostMapping("/home/hot")
    public Result<List<H5TripGroupDTO>> tripHotInfo(@RequestBody @Valid LocalHotSearchReq req) {
        return Result.success(iSeriesTripAppService.getH5HotGroupInfo(req));
    }

    @ApiOperation(value = "旅行团首页-搜索栏-旅游分类", notes = "旅行团首页-搜索栏-旅游分类")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团首页-搜索栏-旅游分类", operDesc = "旅行团首页-搜索栏-旅游分类")
    @GetMapping("/home/catalog")
    public Result getCatalogInfo() {
        return iSeriesTripAppService.getTripHomeH5CatalogDTO();
    }

    @ApiOperation(value = "旅行团-搜索", notes = "旅行团-搜索")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团-搜索", operDesc = "旅行团-搜索")
    @PostMapping("/search")
    public Result<TripH5SearchResDTO> getTripSearch(@RequestBody @Valid TripSearchReq req) {
        return Result.success(iSeriesTripAppService.getTripsByParamsFromH5(req));
    }

    @ApiOperation(value = "旅行团详情", notes = "旅行团详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情", operDesc = "旅行团详情")
    @PostMapping("/details")
    public Result<TripDetailsH5ResDTO> getTripSearch(@RequestBody @Valid TripDetailsReq req) {
        req.setUserId(getCurrentUserAllowNotLogInUserId());
        return iSeriesTripAppService.getH5TripDetails(req);
    }

    @ApiOperation(value = "旅行团详情-费用说明", notes = "旅行团详情-费用说明")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情-费用说明", operDesc = "旅行团详情-费用说明")
    @PostMapping("/details/expense-description")
    public Result<TripExpenseDescriptionDTO> expenseDescription(@RequestBody @Valid TripDetailsReq req) {
        return iSeriesTripAppService.expenseDescription(req);
    }

    @ApiOperation(value = "旅行团详情-报名须知", notes = "旅行团详情-报名须知")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情-报名须知", operDesc = "旅行团详情-报名须知")
    @PostMapping("/details/enrolment-instructions")
    public Result<String> signNotice(@RequestBody @Valid TripDetailsReq req) {
        return iSeriesTripAppService.signNotice(req);
    }

    @ApiOperation(value = "旅行团详情-备注", notes = "旅行团详情-备注")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情-备注", operDesc = "旅行团详情-备注")
    @PostMapping("/details/remark")
    public Result<String> remark(@RequestBody @Valid TripDetailsReq req) {
        return iSeriesTripAppService.remark(req);
    }

    @ApiOperation(value = "旅行团详情-相关推荐", notes = "旅行团详情-相关推荐")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情-相关推荐", operDesc = "旅行团详情-相关推荐")
    @PostMapping("/details/recommends")
    public Result<List<TripsRecommendDTO>> recommends(@RequestBody @Valid TripRecommendReq req) {
        return Result.success(iSeriesTripAppService.recommends(req));
    }

    @ApiOperation(value = "旅行团详情-查看出发日期&价格", notes = "旅行团详情-查看出发日期&价格")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团详情-查看出发日期&价格", operDesc = "旅行团详情-查看出发日期&价格")
    @PostMapping("/details/date-price")
    public Result<List<ScheduleInfoCacheDTO>> dateAndPrice(@RequestBody @Valid TripDetailsDateReq req) {
        return iSeriesTripAppService.dateAndPrice(req);
    }

    @ApiOperation(value = "旅行团-下单页-行程标题&副标题", notes = "旅行团-下单页-行程标题&副标题")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团-下单页-行程标题&副标题", operDesc = "旅行团-下单页-行程标题&副标题")
    @GetMapping("/search/title/{tripNumber}")
    public Result<TripTitleDTO> queryTripTitle(@PathVariable("tripNumber") String tripNumber) {
        return Result.success(iSeriesTripAppService.queryTripTitle(tripNumber));
    }

    @ApiOperation(value = "旅行团-查询分社列表", notes = "旅行团-查询分社列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团-查询分社列表", operDesc = "旅行团-查询分社列表")
    @PostMapping("/search/branch")
    public Result<List<BranchOfficeListDTO>> queryBranchList(@RequestBody BranchQueryReq req) {
        return Result.success(iSeriesTripAppService.queryBranchList(req));
    }

    @ApiOperation(value = "旅行团-分社详情", notes = "旅行团-分社详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.QUERY, operTitle = "旅行团-分社详情", operDesc = "旅行团-分社详情")
    @GetMapping("/search/branch/{branchId}")
    public Result<BranchOfficeDetailsDTO> queryBranchDetails(@PathVariable("branchId") String branchId) {
        return Result.success(iSeriesTripAppService.queryBranchDetails(branchId));
    }

    @ApiOperation(value = "旅行团-详情-收藏", notes = "旅行团-详情-收藏")
    @OperationLogAnnotation(operModul = OperationLogModel.TOUR, operType = OperationLogType.ADD, operTitle = "旅行团-详情-收藏", operDesc = "旅行团-详情-收藏")
    @PostMapping("/favorites")
    public Result favorites(@RequestBody @Valid FavoritesReq req) {
        TokenUser user = getCurrentUser();
        return Result.success(iSeriesTripAppService.favorites(req,user));
    }

}
